package com.koron.ticket.work.logicticket.electricalsecond.controller;

import com.koron.bean.base.Response;
import com.koron.bean.workflow.SubmitterParam;
import com.koron.bean.workflow.WorkflowUser;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.ticket.work.logicticket.electricalsecond.service.ElectricalSecondService;
import com.koron.ticket.work.workticket.service.WorkTicketService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("work/electricalsecond/workflow")
@Api(tags = "两票管理-工作票-电气第二种工作票-插件")
public class ElectricalSecondWorkflowController {

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @Autowired
    private ElectricalSecondService electricalSecondService;


    @Autowired
    private WorkTicketService workticketservice;

    @PostMapping("/draftwrite/handler")
    public Response<List<WorkflowUser>> draftwrite(@RequestBody SubmitterParam submitterParam) {
        return null;
    }

    @PostMapping("/callsign/handler")
    public Response<List<WorkflowUser>> callsign(@RequestBody SubmitterParam submitterParam) {
        //选择 签发人
//        List<WorkflowUser> list = getWorkflowUsers(submitterParam, "办公室", 2);
//        List<WorkflowUser> thisUnitlist = getWorkflowUsers(submitterParam, null, 1);
//        List<WorkflowUser> list = workticketservice.getWorkflowUsers(submitterParam, "办公室", 2);
        List<WorkflowUser> list = workticketservice.getWorkflowUsers(submitterParam, null, 2);//20220607 需求变更 选开票单位的所在部门
//        List<WorkflowUser> thisUnitlist = workticketservice.getWorkflowUsers(submitterParam, null, 1);
//        list.addAll(thisUnitlist);
        return Response.success(list);
    }

//    @ApiOperation("会签测试")
    @PostMapping("/callcountersign/handler")
    public Response<List<WorkflowUser>> callcountersign(@RequestBody SubmitterParam submitterParam) {
        //选择 会签人
//        List<WorkflowUser> list = getWorkflowUsers(submitterParam, "办公室", 2);
//        List<WorkflowUser> listOne = workticketservice.getWorkflowUsers(submitterParam, "办公室", 2);
        List<WorkflowUser> listOne = workticketservice.getWorkflowUsers(submitterParam, null, 2);//20220607 需求变更 选开票单位的所在部门
//        List<WorkflowUser> listTwo = workticketservice.getWorkflowUsers(submitterParam, "", 1);
//        listOne.addAll(listTwo);
        return Response.success(listOne);
    }


    @PostMapping("/callaccept/handler")
    public Response<List<WorkflowUser>> callacceptOper(@RequestBody SubmitterParam submitterParam) {
        //选择 接收人
//        List<WorkflowUser> list = getWorkflowUsers(submitterParam, null, 1);
        List<WorkflowUser> list = workticketservice.getWorkflowUsers(submitterParam, null, 1);
        return Response.success(list);
    }

    @PostMapping("/callaccept/submitter")
    public Response<List<WorkflowUser>> callaccept(@RequestBody SubmitterParam submitterParam) {
        //选择 待许可人
//        List<WorkflowUser> list = getWorkflowUsers(submitterParam, null, 1);
        List<WorkflowUser> list = workticketservice.getWorkflowUsers(submitterParam, null, 4);
        return Response.success(list);
    }

    @PostMapping("/callpermit/submitter")
    public Response<List<WorkflowUser>> callpermit(@RequestBody SubmitterParam submitterParam) {
        //选择 待工作终结人
//        List<WorkflowUser> list = getWorkflowUsers(submitterParam, null, 1);
        List<WorkflowUser> list = workticketservice.getWorkflowUsers(submitterParam, null, 4);
        return Response.success(list);
    }

    @PostMapping("/callworkend/submitter")
    public Response<List<WorkflowUser>> callworkend(@RequestBody SubmitterParam submitterParam) {
        //选择 待工作票终结人
//        List<WorkflowUser> list = getWorkflowUsers(submitterParam, null, 1);
        List<WorkflowUser> list = workticketservice.getWorkflowUsers(submitterParam, null, 4);
        return Response.success(list);
    }


}
